<?php
/**
  * 操作员添加
  * operatorAdd.php
  * 模板文件：operatorAdd.html
  */
include_once("global.php");
include_once("functions/operator.php");

$operator = new operator;

//$DB->debug = true;
//取得参数
$user 	= trim($_REQUEST["user"]);
$pass	= $_REQUEST["pass"];
$pass2	= $_REQUEST["pass2"];
$name	= $_REQUEST["name"];
$email	= $_REQUEST["email"];
$optype	= $_REQUEST["optype"];
$status	= $_REQUEST["status"];
$code	= $_REQUEST["code"];
$chk	= $_REQUEST["chk"];
//
if($act == 2){
	$operator->operator_del($op_id);
}

$errmsg = "";
if($chk == 1){
	if(empty($user))	$errmsg .= "用户名为空！<br/>";
	if($operator->chkuser($user) == false) $errmsg .= "此账号已被占用！<br/>";
	if(empty($pass))	$errmsg .= "密码为空！<br/>";
	if($pass != $pass2)	$errmsg .= "两次密码不一样！<br/>";
	if(empty($code))	$errmsg .= "操作员编码为空！";
}

if($chk == 1 && $errmsg == ""){
	$operator->add_operator($user, $pass, $name, $optype, $email, $status, $code);
	$errmsg = "添加成功！";
}
//模板设置
$smarty = $COMMON->template_init();

//操作员类型
foreach($GLOBAL['DATA']->opType as $k => $v) {
	if($k == $optype) $selected = "selected";
	else $selected = "";
	$optype_list[] = array(
			"key" 		=> $k,
			"value"		=> $v,
			"selected"	=> $selected,
			);
}
//
//操作员状态
foreach($GLOBAL['DATA']->opStatus as $k => $v) {
	if($k == $status) $selected = "selected";
	else $selected = "";
	$status_list[] = array(
			"key" 		=> $k,
			"value"		=> $v,
			"selected"	=> $selected,
			);
}
//


$smarty -> assign(array(
			"errmsg"		=> $errmsg,
			"op_id"			=> $GLOBAL["OP_ID"],
			"user"			=> $user,
			"name"			=> $name,
			"email"			=> $email,
			"code"			=> $code,
			"optype_list"	=> $optype_list,
			"status_list"	=> $status_list,
			"show_contact"	=> "contact_show.php?",
		));

$smarty->display("operatorAdd.html");
?>